package Solution201_220;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution208 {
    class Trie {

        Set<String> wordD;
        StringBuilder wordB;

        /** Initialize your data structure here. */
        public Trie() {
            wordD=new HashSet<>();
            wordB=new StringBuilder();
        }

        /** Inserts a word into the trie. */
        public void insert(String word) {
            wordD.add(word);
            wordB.append(word);

        }

        /** Returns if the word is in the trie. */
        public boolean search(String word) {
            return wordD.contains(word);
        }

        /** Returns if there is any word in the trie that starts with the given prefix. */
        public boolean startsWith(String prefix) {
            return wordB.toString().startsWith(prefix);
        }
    }
}
